package com.xiaoran;

import java.lang.reflect.Proxy;

/**
 * @author xiaoRan
 */
public class UserServiceImpl implements UserService {
    private UserMapper userMapper = getUserMapper();

    @Override
    public User getUserById(Integer id) {
        return userMapper.getById(id);
    }

    /**
     * 获取 userMapper 代理对象
     *
     * @return userMapper
     */
    public UserMapper getUserMapper() {
        UserInvocationHandler userInvocationHandler = new UserInvocationHandler();
        return (UserMapper) Proxy.newProxyInstance(UserMapper.class.getClassLoader(), new Class<?>[]{UserMapper.class}, userInvocationHandler);
    }
}
